package org.melanesia.sql;

import java.util.Collection;
import java.util.LinkedHashMap;
import java.util.Map;

import org.melanesia.converters.JavaToJavaConverter;

/**
 * This is a helper class, for storing call metadata, like input/output
 * parameters, type converters, etc.
 *
 * @author marcin.kielar
 */
class CallMetaData extends QueryMetaData {

    /** Collection storing output parameters registered with {@link Call}. */
    private final Map<String, OutputParameter> outputParameters = new LinkedHashMap<String, OutputParameter>();

    /**
     * Returns the collection of registered output parameter names.
     *
     * @return collection of registered output parameter names
     */
    final Collection<String> getOutputParameterNames() {
        return outputParameters.keySet();
    }

    /**
     * Returns the output parameter metadata for the parameter of given name.
     *
     * @param name
     *            parameter name
     * @return parameter metadata
     */
    final OutputParameter getOutputParameter(final String name) {
        return outputParameters.get(name);
    }

    /**
     * Registers outputParameter.
     *
     * This method allows for explicit specification of
     * {@link org.melanesia.converters.JavaToJavaConverter} to be used for this
     * parameter, as well as the jdbc type of the returned parameter value.
     *
     * @param name
     *            parameter name
     * @param parameterClass
     *            parameter class
     * @param jdbcType
     *            optional jdbc type
     * @param databaseTypeName
     *            optional database type name for user-defined database types
     * @param converter
     *            optional java to java converter
     */
    final void registerOutputParameter(final String name, final Class<?> parameterClass, final Integer jdbcType,
            final String databaseTypeName, final JavaToJavaConverter converter) {
        outputParameters.put(name, new OutputParameter(name, parameterClass, jdbcType, databaseTypeName, converter));
    }
}
